package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* SemiCircleDepthProgressView2
* */
class SemiCircleDepthProgressView2 @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mStrokeWidth = context.resources.getDimension(R.dimen.dp_2)

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeWidth = mStrokeWidth
            style = Paint.Style.STROKE
            color = context.resources.getColor(R.color.color_A80FDF)
        }
    }

    private val mPaint1 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            style = Paint.Style.FILL
            color = context.resources.getColor(R.color.color_D68AF1)
        }
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            translate(cx, cy - (cy - cy * 2 / 5) / 2)
            val arcX = cx * 3 / 5
            val arcY = cy * 3 / 5
            drawArc(
                -arcX,
                -arcY,
                arcX,
                arcY,
                0F,
                180F,
                false,
                mPaint0
            )

            val offsetAngle = 75F
            drawArc(
                -arcX + mStrokeWidth,
                -arcY + mStrokeWidth,
                arcX - mStrokeWidth,
                arcY - mStrokeWidth,
                90F - offsetAngle,
                offsetAngle * 2,
                false,
                mPaint1
            )

//            drawArc(
//                -arcX + mStrokeWidth / 2,
//                -arcY + mStrokeWidth / 2,
//                arcX - mStrokeWidth / 2,
//                arcY - mStrokeWidth / 2,
//                90F - offsetAngle,
//                offsetAngle * 2,
//                false,
//                mPaint1
//            )
        }
    }
}